package com.rr.middle;

import java.util.Arrays;

/**
 * https://leetcode.cn/problems/boats-to-save-people/?envType=daily-question&envId=2024-06-10
 * 贪心算法   注意题意，一艘船最多载2人
 */
public class NumRescueBoats {

    public int numRescueBoats(int[] people, int limit) {
        Arrays.sort(people);
        int left = 0;
        int right = people.length - 1;
        int result = 0;
        while (left <= right) {
            if (people[left] + people[right] <= limit) {
                ++left;
            }
            right--;
            result++;
        }
        return result;
    }

    public static void main(String[] args) {
        NumRescueBoats numRescueBoats = new NumRescueBoats();
        System.out.println(numRescueBoats.numRescueBoats(new int[] {1, 2}, 3));

    }
}
